package com.lizonghui.googleplay.factory;

import com.lizonghui.googleplay.base.BaseFragment;
import com.lizonghui.googleplay.fragment.AppFragment;
import com.lizonghui.googleplay.fragment.CategoryFragment;
import com.lizonghui.googleplay.fragment.GameFragment;
import com.lizonghui.googleplay.fragment.HomeFragment;
import com.lizonghui.googleplay.fragment.HotFragment;
import com.lizonghui.googleplay.fragment.RecommendFragment;
import com.lizonghui.googleplay.fragment.SubjectFragment;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/6/16.
 * 生产出fragment
 */
public class FragmentFactory {

    public static final int FRAGMENT_HOME      = 0;//首页
    public static final int FRAGMENT_APP       = 1;//应用
    public static final int FRAGMENT_GAME      = 2;//游戏
    public static final int FRAGMENT_SUBJECT   = 3;//专题
    public static final int FRAGMENT_RECOMMEND = 4;//推荐
    public static final int FRAGMENT_CATEGORY  = 5;//分类
    public static final int FRAGMENT_HOT       = 6;//排行

    public static Map<Integer,BaseFragment> mFragmentMap  = new HashMap<>();

    //这里返回Fragment，注意是V4包中的Fragment
    public static BaseFragment createFragment(int position) {
        BaseFragment fragment = null;
        //判断该集合中是否有该position的Fragment存在
        if(mFragmentMap.containsKey(position)){
            fragment = mFragmentMap.get(position);
            return fragment;
        }
        switch (position) {
            case FRAGMENT_HOME:
                fragment  = new HomeFragment();
                break;
            case FRAGMENT_APP:
                fragment  = new AppFragment();
                break;
            case FRAGMENT_GAME:
                fragment  = new GameFragment();
                break;
            case FRAGMENT_SUBJECT:
                fragment  = new SubjectFragment();
                break;
            case FRAGMENT_RECOMMEND:
                fragment  = new RecommendFragment();
                break;
            case FRAGMENT_CATEGORY:
                fragment  = new CategoryFragment();
                break;
            case FRAGMENT_HOT:
                fragment  = new HotFragment();
                break;
            default:
                break;
        }
        //加入集合中
        mFragmentMap.put(position,fragment);
        return fragment;
    }
}
